from .base_model import BaseModel
from django.db import models
from datetime import date, timedelta
from core.models.grade_schedule import GradeSchedule
from core.models.classinfo import ClassInfo
class Student(BaseModel):
    """学生模型"""
    id = models.AutoField(primary_key=True, verbose_name="学生ID")
    name=models.CharField(max_length=10, verbose_name="姓名")
    #生日
    birthday=models.DateField(default=date.today, verbose_name="生日")

    @property
    def age(self):
        today = date.today()
        age = today.year - self.birthday.year
        if (today.month, today.day) < (self.birthday.month, self.birthday.day):
            age -= 1
        return age
    gender = models.CharField(max_length=1, choices=[('M', '男'), ('F', '女')], verbose_name="性别")
    enrollment_date = models.DateField(default=date.today, verbose_name="入学日期")
    contact_info = models.CharField(max_length=100, blank=True, verbose_name="联系方式")
    home_address = models.CharField(max_length=200, blank=True, verbose_name="家庭住址")
    family_background = models.TextField(blank=True, verbose_name="家庭情况备注")
    classes = models.ManyToManyField(ClassInfo, through='StudentClassEnrollment', related_name='enrolled_students', verbose_name="班级")

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "学生"
        verbose_name_plural = "学生"
  